package edu.whu.demo.controller;


import edu.whu.demo.domain.Comm_supp;
import edu.whu.demo.service.impl.Comm_suppServiceImpl;
import edu.whu.demo.service.impl.Comm_suppServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zxj
 * @since 2023-10-18
 */
@RestController
@RequestMapping("/comm_supp")
public class Comm_suppController {
    @Autowired
    Comm_suppServiceImpl comm_suppService;

    @PostMapping("/add")
    @PreAuthorize("hasAuthority('commodity/change')")
    public ResponseEntity<Comm_supp> addComm_supp(Comm_supp comm_supp){
        Comm_supp comm_supp1 = comm_suppService.addComm_supp(comm_supp);
        return ResponseEntity.ok(comm_supp1);
    }

    @PostMapping("/del")
    @PreAuthorize("hasAuthority('commodity/change')")
    public ResponseEntity<Void> deleteComm_supp(int id){
        comm_suppService.delComm_suppById(id);
        return ResponseEntity.ok().build();
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('commodity/change')")
    public ResponseEntity<Void> updateComm_supp(Comm_supp Comm_supp){
        comm_suppService.updateComm_suppById(Comm_supp);
        return ResponseEntity.ok().build();
    }

    @PostMapping("/find")
    @PreAuthorize("hasAuthority('commodity/findAllSuppliers')")
    public ResponseEntity<Comm_supp> findComm_suppById(int id){
        Comm_supp comm_supp = comm_suppService.findComm_suppById(id);
        return ResponseEntity.ok(comm_supp);
    }


}

